import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('wgq', () => {
  let shop = ref([])
  function shopcar(wgq, goodsid) {
    console.log('数据', wgq)
    console.log('数据', goodsid)
    let username = localStorage.getItem('username')
    let userdata = shop.value.filter(item => item.username == username)
    let userid = userdata.find(item => item.goods.goods_id == goodsid)
    if (userid) {
      userid.number++
    }
    else {
      shop.value.push({
        username: username,
        id: Math.floor(Math.random() * 10000),
        goods: wgq,
        checked: false,
        number: 1,
      })
    }
  }
  return { shop, shopcar }
}, {
  persist: true,
},)
